package com.ifast.oupei.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ifast.oupei.dao.LeagueDao;
import com.ifast.oupei.domain.LeagueDO;
import com.ifast.oupei.service.LeagueService;
import com.ifast.oupei.vo.LeagueVO;
import com.baomidou.mybatisplus.plugins.Page;
import com.ifast.common.base.CoreServiceImpl;

/**
 * 
 * <pre>
 * 联赛信息表
 * </pre>
 * 
 * <small> 2018-04-19 10:02:56 | Aron</small>
 */
@Service
public class LeagueServiceImpl extends CoreServiceImpl<LeagueDao, LeagueDO> implements LeagueService {

	@Autowired
	LeagueDao leagueDao;

	@Override
	public List<String> listAllLeagueName() {

		return leagueDao.listAllLeagueName();
	}

	@Override
	public List<String> listAllSeaon(String leagueName) {
		return leagueDao.listAllSeaon(leagueName);
	}

	@Override
	public List<LeagueVO> listAllTurn(String leagueName, String season) {
		List<LeagueDO> leagueDOList = leagueDao.listAllTurn(leagueName, season);
		List<LeagueVO> leagueVOList = new ArrayList<LeagueVO>();
		int totalTurn = 0;
		for (LeagueDO leagueDO : leagueDOList) {
			try {// 如果是数字格式，显示1-totalTurn之间数字
				totalTurn = Integer.parseInt(leagueDO.getTotalTurn());
				for (int i = 0; i < totalTurn; i++) {
					leagueVOList.add(new LeagueVO(String.valueOf(i + 1), String.valueOf(i + 1)));
				}
			} catch (Exception e) {
				leagueVOList.add(new LeagueVO(leagueDO.getCupMatchCode(), leagueDO.getCupMatchDetail()));
			}
		}
		return leagueVOList;
	}

	@Override
	public Page<LeagueDO> ListAllLeagueInfo(Page<LeagueDO> page) {
		page.setRecords(leagueDao.ListAllLeagueInfo(page));
		return page;
	}
	@Override
	// 获取所有轮次
	public List<LeagueDO> listLeague(String leagueName, String season) {
		return leagueDao.listAllTurn(leagueName, season);
	}
	@Override
	// 获取所有轮次
	public List<LeagueDO> listLeague(String leagueName, String season,String cupMatchDetail) {
		return leagueDao.listAllTurn2(leagueName, season, cupMatchDetail);
	}
	// 根据联赛名称获取所以的联赛信息 
	@Override
	public List<LeagueDO> listLeagueByName(String leagueName) {
		return leagueDao.listLeagueByName(leagueName);
	}

	//获取默认赛季
	@Override
	public LeagueDO getSeason(String name){
		return leagueDao.getSeason(name);
	}
}
